<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="回复内容" prop="localReplyText">
        <el-input
          v-model="queryParams.localReplyText"
          placeholder="请输入回复内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['local:reply:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['local:reply:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="replyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="回复编号" align="center" prop="localReplyId" />
      <el-table-column label="回复内容" align="center" prop="localReplyText" :show-overflow-tooltip="true"/>
      <el-table-column label="回复人" align="center" prop="customerInfo.customerName" />
      <el-table-column label="回复标题ID" align="center" prop="localReviers.localReviewsTitle" />
      <el-table-column label="父ID" align="center" prop="localReplyParent" />
      <el-table-column label="点赞数" align="center" prop="localReplyFabulous" />
      <el-table-column label="回复量" align="center" prop="localReplyNumber" />
      <el-table-column label="回复时间" align="center" prop="localReplyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.localReplyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['local:reply:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!--    &lt;!&ndash; 添加或修改本地用户评论回复对话框 &ndash;&gt;-->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="回复内容" prop="localReplyText">-->
<!--          <el-input v-model="form.localReplyText" placeholder="请输入回复内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="回复人" prop="localReplyCustomer">-->
<!--          <el-input v-model="form.localReplyCustomer" placeholder="请输入回复人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="回复标题ID" prop="localReviersId">-->
<!--          <el-input v-model="form.localReviersId" placeholder="请输入回复标题ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="父ID" prop="localReplyParent">-->
<!--          <el-input v-model="form.localReplyParent" placeholder="请输入父ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="点赞数" prop="localReplyFabulous">-->
<!--          <el-input v-model="form.localReplyFabulous" placeholder="请输入点赞数" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="回复时间" prop="localReplyTime">-->
<!--          <el-date-picker clearable size="small" style="width: 200px"-->
<!--            v-model="form.localReplyTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="选择回复时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listReply, getReply, delReply, addReply, updateReply, exportReply } from "@/api/customer/reply";

export default {
  name: "Reply",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 本地用户评论回复表格数据
      replyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        localReplyText: null,
      },
      // 表单参数
      form: {},
      // // 表单校验
      // rules: {
      //   localReplyText: [
      //     { required: true, message: "回复内容不能为空", trigger: "blur" }
      //   ],
      //   localReplyCustomer: [
      //     { required: true, message: "回复人不能为空", trigger: "blur" }
      //   ],
      //   localReviersId: [
      //     { required: true, message: "回复标题ID不能为空", trigger: "blur" }
      //   ],
      //   localReplyParent: [
      //     { required: true, message: "父ID不能为空", trigger: "blur" }
      //   ],
      //   localReplyFabulous: [
      //     { required: true, message: "点赞数不能为空", trigger: "blur" }
      //   ],
      //   localReplyTime: [
      //     { required: true, message: "回复时间不能为空", trigger: "blur" }
      //   ]
      // }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询本地用户评论回复列表 */
    getList() {
      this.loading = true;
      listReply(this.queryParams).then(response => {
        this.replyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // // 取消按钮
    // cancel() {
    //   this.open = false;
    //   this.reset();
    // },
    // // 表单重置
    // reset() {
    //   this.form = {
    //     localReplyId: null,
    //     localReplyText: null,
    //     localReplyCustomer: null,
    //     localReviersId: null,
    //     localReplyParent: null,
    //     localReplyFabulous: null,
    //     localReplyTime: null
    //   };
    //   this.resetForm("form");
    // },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.localReplyId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加本地用户评论回复";
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const localReplyId = row.localReplyId || this.ids
    //   getReply(localReplyId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改本地用户评论回复";
    //   });
    // },
    // /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.localReplyId != null) {
    //         updateReply(this.form).then(response => {
    //           if (response.code === 200) {
    //             this.msgSuccess("修改成功");
    //             this.open = false;
    //             this.getList();
    //           }
    //         });
    //       } else {
    //         addReply(this.form).then(response => {
    //           if (response.code === 200) {
    //             this.msgSuccess("新增成功");
    //             this.open = false;
    //             this.getList();
    //           }
    //         });
    //       }
    //     }
    //   });
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const localReplyIds = row.localReplyId || this.ids;
      this.$confirm('是否确认删除本地用户评论回复编号为"' + localReplyIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delReply(localReplyIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有本地用户评论回复数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportReply(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
